﻿using System;
using System.Collections.Generic;

class ThreeTaskProgram
{
    static void ReverseDigits(List<int> ListOfInts, decimal numberToReverse)
    {
        int i = numberToReverse.ToString().Length;
        for (int j = 0; j < i; j++)
        {
            ListOfInts.Add((int)numberToReverse % 10);
            numberToReverse = numberToReverse / 10;
        }
        Console.WriteLine();
        foreach (int value in ListOfInts)
        {
            Console.Write(value);
        }
    }
    static void GetAverege(int[] array, double average)
    {
        Console.WriteLine("The sequence you entered is:");
        for (int i = 0; i < array.Length; i++)
        {
            Console.Write("{0,3}",array[i]);
        }
        Console.WriteLine();
        Console.WriteLine("The average number is {0}",average/array.Length);
    }
    static void LinearEquation()
    { 
        Console.WriteLine("Enter coeficient a (a != 0):");
        double a = double.Parse(Console.ReadLine());
        if (a == 0)
        {
            Console.WriteLine("Invalid input!");
        }
        else
        {
            Console.WriteLine("Enter coeficient b:");
            double b = double.Parse(Console.ReadLine());
            double x = -b / a;
            Console.WriteLine("x = {0}", x);
        }
    }
    static void Main()
    {
        double averageNumber = 0.0d;
        Console.WriteLine("Enter what do you want to do.");
        Console.WriteLine("Enter 1 to reverse digits of a number;");
        Console.WriteLine("Enter 2 to see the average number of a sequance;");
        Console.WriteLine("Enter 3 to solve the linear equation: a*x + b = 0.");
        int choice = int.Parse(Console.ReadLine());
        switch(choice)
        {
            case 1:
                {
                    Console.WriteLine("Enter a number to reverse it's digits:");
                    decimal numberEntered = decimal.Parse(Console.ReadLine());
                    List<int> ListOfDigits = new List<int>();
                    ReverseDigits(ListOfDigits, numberEntered);
                    break;
                }
            case 2:
                {
                    Console.WriteLine("Enter the number of elements of the array:");
                    int dimension = int.Parse(Console.ReadLine());
                    int[] arrayOfInts = new int[dimension];
                    Console.WriteLine("Enter the sequence(array) of integers:");
                    for (int index = 0; index < dimension; index++)
                    {
                        Console.WriteLine("Enter element {0}:",index);
                        arrayOfInts[index] = int.Parse(Console.ReadLine());
                        averageNumber += arrayOfInts[index];
                    }
                    GetAverege(arrayOfInts, averageNumber);
                    break;
                }
            case 3:
                {
                    LinearEquation();
                    break;
                }
            default:
                {
                    Console.WriteLine("Your choice is not in range (1 - 3)!");
                    break;
                }
        }
    }
}

